<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="/WEB-INF/common/hplus-css.jsp"%>
    <link href="${path}/assets/hplus/css/plugins/jqgrid/ui.jqgrid.css?0820" rel="stylesheet">
	<link href="${path}/assets/publicSecurity/css/gonganQuery.css" rel="stylesheet">
	
	<c:if test="${User.type eq '2'  }">
		<style type="text/css">
			.ibox-content{text-align: left;}
		</style>
	</c:if>
</head>
<body>
<!-- 顶部导航开始 -->
	<c:if test="${User.type eq '2'  }">
		<%@include file="/WEB-INF/common/header.jsp"%>
	</c:if>
	<!-- 顶部导航结束 -->
    <div class="wrapper wrapper-content  animated fadeInRight" <c:if test="${User.type eq '2'  }"> style="text-align: -webkit-center;text-align: -moz-center;"</c:if>>
        <div class="row" id="test01">
            <div <c:if test="${User.type eq '2'  }"> style="width:80%;"</c:if>>
                <div class="ibox ">
                    <div class="ibox-title">
                        <h5>用户管理</h5>
                        <c:if test="${User.type eq '2'  }">
							<a href="javascript:history.back(-1)">
								<div class="center-topssss " style="margin-top: -6px;">
								<b>返回</b>
								</div>
							</a>
						</c:if>
                    </div>
                    <div class="ibox-content">
                        <form action="${path}/user/query" role="form" class="form-inline query-form">
                            <div class="form-group">
                                <label for="name" class="sr-only">用户名</label>
                                <input type="text" placeholder="请输入用户名" id="name" name="name" class="form-control">
                            </div>
                            <button type="button" id="btn-query" class="btn btn-primary">查询</button>
                            <button type="button" id="btn-reset" class="btn btn-warning">重置</button>
                        </form>
                        <div class="jqGrid_wrapper">
                            <table id="table_user"></table>
                            <div id="pager_user"></div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
	

    <%@include file="/WEB-INF/common/hplus-js.jsp"%>

    <script type="text/javascript">
        $(document).ready(function () {
            $.jgrid.defaults.styleUI = 'Bootstrap';
            $("#table_user").jqGrid({
            	url : "${path}/member/query",
                mtype : "POST",
                datatype : "JSON",
                jsonReader:{
                   	id: "id", //相当于设置主键
		           	root: "result",//Json数据
		           	total: "allPage",//总页数
					page: "page", //当前页
					records: "allCount",//总记录数
					repeatitems: false
                },
                altRows: true,//单双行样式不同
                altclass: 'differ',
                autowidth: true,
                shrinkToFit: true,
                height:353,
                rowNum: 10,
                rowList: [10, 20, 50],
                colNames: ['微信昵称', '手机号码', '注册时间'],
                colModel: [{
                        name: 'name',
                        index: 'name',
                        width: 20
                    },{
                        name: 'mobile',
                        index: 'mobile',
                        width: 25
                    },{
            	        name:'createDate',
                        index:'createDate',
                        width:10
                    }
                ],
                pager: "#pager_user",
                viewrecords: true,
                hidegrid: false,
                loadonce: false
            });
            $(window).bind('resize', function () {
                var width = $('.jqGrid_wrapper').width();
                $('#table_user').setGridWidth(width);
            });
            $(window).trigger("resize");
            $("#btn-add").click(function(){
            	layer.open({
                    type: 2,
                    title: '添加用户',
                    shadeClose: true,
                    shade: 0.5,
                    area: ['80%', '80%'],
                    content: '${path}/user/add' //iframe的url
                });
            });
            $("#btn-query").click(function(){
            	$("#table_user").jqGrid('setGridParam', {
                    url : "${path}/member/query",
                    datatype:'json',
                    postData : {
                    	"name":$("#name").val(),
                    	"status":$("#status option:selected").val()
                    }, 
                    page : 1
                }).trigger("reloadGrid"); //重新载入
            });
            
        });
        function editUser(id){
           layer.open({
                type: 2,
                title: '修改用户',
                shadeClose: true,
                shade: 0.5,
                area: ['800px', '460px'],
                content: '${path}/user/edit/' + id //iframe的url
            });
        }
        function enableUser(flag,id,name){
        	var op = (flag?"启用":"禁用");
        	parent.layer.confirm("您确定要"+op+"该用户吗?", {
        	    btn: ['确定','取消'], //按钮
        	    shade: true, //不显示遮罩
        	    shadeClose: true,
                shade: 0.5,
        	}, function(){
        		$.ajax({
                    type: "POST",
                    url: "${path}/user/enable",
                    data:{"status":(flag?1:0),"id":id},
                    dataType: "json",
                    success: function(json){
                        if(json.code == 0){
                        	parent.layer.closeAll();
                        	layer.msg(op+'成功', {icon: 1});
                        	setTimeout(function(){
                        		  $("#table_user").jqGrid('setGridParam', {
					                    url : "${path}/user/query",
					                    datatype:'json',
					                    postData : {
					                    	"idcard":$("#idcard").val(),
					                    	"name":$("#name").val(),
					                    	"mobile":$("#mobile").val(),
					                    	"trueName":$("#trueName").val(),
					                    	"unitOrPolice":$("#unitOrPolice").val(),
					                    	"status":$("#status option:selected").val()
					                    }, 
					                    page : 1
					                }).trigger("reloadGrid"); //重新载入
                            }, 500); 
                        }else{
                        	layer.msg(op + '发生错误:' + json.msg, {icon: 5});
                        }                    
                    }
                });
        		 
        	}, function(){
        	    
        	});
        }
        function  updateBystatus(id,name){
        	if(id == '4028ab7a67210e0b0167215d76cc0001'){
        		layer.msg('该用户禁止删除。', {icon: 7});
        		return false;
        	}
        	parent.layer.confirm("您确定要删除该用户吗?", {
        	    btn: ['确定','取消'], //按钮
        	    shade: true, //不显示遮罩
        	    shadeClose: true,
                shade: 0.5,
        	}, function(){
        		$.ajax({
                    type: "POST",
                    url: "${path}/user/enable",
                    data:{"status":'-3',"id":id},
                    dataType: "json",
                    success: function(json){
                        if(json.code == 0){
                        	parent.layer.closeAll();
                        	layer.msg('删除成功', {icon: 1});
                        	setTimeout(function(){
                                /* location.reload(); */
                                $("#table_user").jqGrid('setGridParam', {
					                    url : "${path}/user/query",
					                    datatype:'json',
					                    postData : {
					                    	"idcard":$("#idcard").val(),
					                    	"name":$("#name").val(),
					                    	"mobile":$("#mobile").val(),
					                    	"trueName":$("#trueName").val(),
					                    	"unitOrPolice":$("#unitOrPolice").val(),
					                    	"status":$("#status option:selected").val()
					                    }, 
					                    page : 1
					                }).trigger("reloadGrid"); //重新载入
                            }, 500); 
                        }else{
                        	layer.msg(op + '发生错误:' + json.msg, {icon: 5});
                        }                    
                    }
                });
        		 
        	}, function(){
        	    
        	});
        }
       
    </script>
</body>
</html>
